<script src="/admins/js/jquery.form.js" type="text/javascript"></script>
<div class="admin_nrtop">
    <div class="ad_search">
        <form action=""  method="get" style="margin:0px" id="form1">
        <div class="search">
            <div class="soubox">分类：                
                <select name="pid" onchange="javascript:$('#form1 select[name=menuid]').val(0);$('#form1').submit();">
                    <?php foreach ($this->menu as $key => $value) { ?>                      
                    <option value="<?php echo $value->id; ?>" <?php if($this->pid==$value->id) echo 'selected'; ?>>
                        <?php echo $value->name;  ?>
                    </option>
                   <?php } ?> 
                </select>             
            </div>           
        </div>
                <div class="search">
            <div class="soubox">                
                <select name="menuid" onchange="javascript:$('#form1').submit();">
                    <option value="0" selected>选择</option>
                    <?php foreach ($this->smenu as $key => $value) { ?>                      
                    <option value="<?php echo $value->id; ?>" <?php if($this->menuid==$value->id) echo 'selected'; ?>>
                        <?php  echo $value->name;  ?>
                    </option>
                   <?php } ?> 
                </select>             
            </div>           
        </div>
        <input type="hidden" id="pagesize" name="pagesize" value="10">
        <div class="xianshi">
            <label>显示：</label>
            <ul>
                <li <?php echo $this->pagesize?($this->pagesize==10?'class="xson"':""):'class="xson"'; ?>><a href="javascript:void(0)" name="10" class="setpagesize">10</a></li>
                <li <?php echo $this->pagesize?($this->pagesize==20?'class="xson"':""):""; ?>><a href="javascript:void(0)" name="20" class="setpagesize">20</a></li>
                <li <?php echo $this->pagesize?($this->pagesize==30?'class="xson"':""):""; ?>><a href="javascript:void(0)" name="30" class="setpagesize">30</a></li>
            </ul>
        </div>
        </form>
    </div>
</div>

<div  class="biaoge">
<style type="text/css">
.soubox{padding-left: 5px;}
.soubox select{width: 228px;    line-height: 30px;    padding: 6px;    border: 0;    outline: navajowhite;}
.table table td{background: #fff;}
</style>
     <div class="biaotbody table">
         <table>
           <tr>
                <th class="li2">
                    <div class="lileft"><span><input type="checkbox" id="checkbox"></span></div>
                </th>
                <th class="li9">
                    <div class="lileft"><span>商品名称</span></div>
                </th>               
               
                <th class="li5">
                    <div class="lileft"><span>商品价格</span></div>
                </th>
                <th class="li5">
                   <div class="lileft"><span>图片</span></div>
                </th>
                <th class="li5">
                    <div class="lileft"><span>分类</span></div>
                </th>  
                <th class="li5">
                    <div class="lileft">操作</div>
                </th>             
            </tr>
             <?php 
                 foreach ($this->generalizeList as $Item) { ?> 
                 <tr>
                     <td class="li2">
                         <div class="lileft">
                          <input type="checkbox" name="goodsid[]" class="goodslist" value="<?php echo $Item->id; ?>">              
                         </div>
                     </td>
                     <td class="li9">
                         <div class="lileft">
                             <?php echo $Item->title;?>
                        </div>
                     </td>                    
                     <td class="li5">
                         <div class="lileft">
                             <?php echo $Item->price;?>
                        </div>
                     </td>
                     <td class="li5">
                         <div class="lileft">
                           <img src="<?php echo $Item->picurl;?>" width="50">
                        </div>
                     </td>                    
                     <td class="li5">
                         <div class="lileft">
                            <?php echo Application_Model_Goodsmenu::getmenuname($Item->menuid);?>   
                        </div>
                     </td>
                     <td class="li5">
                         <div class="lileft">
                        <a class="xlnavxq" href="/admini/goods/goodsdetail/id/<?php echo $Item->Id;?>" >编辑</a>
                         </div>
                     </td>
                 </tr>
             <?php } ?>   
         </table>
     </div>
 </div>

<div class="toolbar">
    <div class="qunx">
        <ul>
<?php if(Application_Model_Goodsmenu::istopmenu($this->menuid)){ ?>
            <li><a class="anvbotton" href="javascript:void(0)"  id="addGeneralize"><span>添加分类banner</span></a></li>
 <?php }else{ ?> 
  <li><a class="anvbotton" href="/admini/goods/addgoods/menuid/<?php echo $this->menuid;?>"><span>添加商品</span></a></li>
 <?php } ?>           
            <li><a class="anvbotton" href="javascript:void(0)" id="editOrder" name="editOrder"><span>删除所选</span></a></li>
        </ul>
    </div>
<?php
    echo $this->partial('paging.phtml', array("pages" => $this->generalizeAll,"pamas"=>"quick=$this->quick&timescope=$this->timescope&starttime=$this->starttime&endtime=$this->endtime&pagesize=$this->pagesize&cityId=$this->cityId&status=$this->status"));        
?>
</div>
<style>
    #add_table{
        width: 600px;
        font-size: 16px;
        padding: 5px;
    }
    #add_table *{
        font-size: 14px;
        padding: 5px;
    }
    #add_table input[type=text]{
    width: 350px;
    }
    #showimg{color: red;}
</style>
<div class="tanchuang" style="display:none;">
    <div class="nui-msgbox">
        <div class="nui-msgbox-hd" id="wayProblem">添加分类banner</div>
        <a class="nui-msgbox-close" title="关闭"><b></b></a>
    </div>
    <div class="wenti_box" id="problemComm">
            <div style="margin-left:30px;margin-top: 15px;margin-bottom: 5px;">
                <table id="add_table">
                    <tr>
                        <td align="center" colspan="2" style="font-size:18px"><?php echo Application_Model_Goodsmenu::getmenuname($this->menuid);?></td>
                    </tr>
                    <tr>
                        <td align="right">标题：</td>
                        <td><input type="text" id="title" name="title" value="" /></td>
                        
                    </tr>
                    <tr>
                       <td align="right">图片：</td>
                        <td><span id="pic_url"><input type="file" id="pict_url" name="pict_url" value="" />
                        <input type='hidden' name='picpath' value='/goods/'/><span id="showimg"></span></span>
                         </td>
                    </tr>
                    <tr>                        
                        <td align="right">链接：</td>
                        <td><input type="text" id="item_url" name="item_url" value="" /></td>
                    </tr>
                    <tr>                        
                        <td align="right">专题背景色：</td>
                        <td><input type="color" id="color" name="color" value="" /></td>
                    </tr>
                   <tr>                        
                        <td align="right">　</td>
                        <td></td>
                    </tr>
                    <tr>
                        <td align="center"  colspan="2">                            
                            <input type="hidden" id="menuid" name="menuid" value="<?php echo $this->menuid;?>" />  
                             <input type='hidden' value='' id='imgpath' name='imgpath'>
                            <input type="button" id="navigationAdd" naem="navigationAdd" value="添加" style="background-color: #F60;width: 50px;height: 36px;color: white;font-size: 16px;border-radius:8px;"/>
                            &nbsp;&nbsp;<input type="button" id="refo" naem="refo" value="返回" style="background-color: #1668A4;width: 50px;height: 36px;color: white;font-size: 16px;border-radius:8px;"/>
                        </td>
                    </tr>
                </table>
            </div>
    </div>
</div>
<script>
    $(function(){
       $(".setpagesize").click(function(){
          var pagesize = $(this).attr("name");
          $("#form1 #pagesize").val(pagesize);
          $("#form1").submit();
       });

      $("#checkbox").click(function(){        
        if ($(this).attr('checked') =='checked') {
          $(".table .goodslist").attr('checked',true);
        }else{
          $(".table .goodslist").attr('checked',false);
        }        
       });

         $("#addGeneralize").click(function(){
                $(".tanchuang").show();
            });
         $(".nui-msgbox-close").click(function(){      
        $(".tanchuang").hide();
         })
    $("#navigationAdd").click(function(){ 
        var menuid = $("#menuid").val();        
        var title = $("#title").val();      
        var pict_url = $("#imgpath").val();        
        var item_url = $("#item_url").val();
        var color = $("#color").val();
        if(title == ""){
            alert("导航名称不能为空");
            return ;
        }
        $.post('/admini/goods/addbanner', {'id':menuid,'item_url':item_url,'title':title,"pict_url":pict_url,"color":color}, function(sj){
             if(sj == 1){
                 alert("添加成功！");
                 location.href = "/admini/goods/index?menuid="+menuid;
             }else{
                 alert("出现未知错误");
             }
        }, 'json');
       
    });

        $("#editOrder").click(function(){
        var delAll = "";
        var parentId = $("#parentId").val();
        var isOrder = false;
        $.each($("input[name='goodsid[]']"), function(i,val){ 
            if(val.value == ""){
                alert("排序值不能为空");
                isOrder = true;
                return ;
            }
            delAll += val.value+",";   
        });
        if(isOrder){
            return ;
        }
        $.post("/admini/goods/delgoods",{"delAll":delAll},function(date){
            if(date == 1){
                 alert("删除成功");
                 location.href = "/admini/goods/index/?menuid=<?php echo $this->menuid;?>";
            }else{
                alert("出现未知错误，请刷新在试。");
            }
        },"json");
    });
    });
</script>

 <script type="text/javascript">
$(function () {
    var showimg = $('#showimg');
    $("#pic_url").wrap("<form id='myupload' action='/admini/ajax/upimg2' method='post' enctype='multipart/form-data'></form>");
    $("#pic_url").change(function(){
        $("#myupload").ajaxSubmit({
            dataType:  'json',                     
            success: function(data) {              
                var img = "http://cdn.uuch.com/goods/"+data.pic;
                $('#imgpath').val(img);
                showimg.html("上传成功");
            },
            error:function(xhr){
                showimg.html("上传失败");
            }
        });
    });
});
</script>